/**
 * 
 */
package com.fatiny.core.proto;

import com.fatiny.util.StringUtils;

/**
 * 协议字段
 */
public class ProtocolField {
	/**
	 * 标识符，repeated、optional
	 */
	private String identifier;
	/**
	 * proto 数据类型
	 */
	private String type;
	/**
	 * 字段名称
	 */
	private String name;
	/**
	 * 备注信息
	 */
	private String comment;

	/**
	 * proto对应的Java类型,
	 */
	private String javaType;
	
	/**
	 * proto对应的Java基础类,泛型类
	 * int,WishClothDtoProto
	 */
	private String javaTypeBase;

	public String getIdentifier() {
		return identifier;
	}

	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		int idx = type.lastIndexOf(".");
		if (idx > 0) {
			type = type.substring(idx + 1, type.length());
		}
		this.type = type;
		this.javaTypeBase = StringUtils.protoTypeToJavaType(type);
		int index = javaTypeBase.lastIndexOf("Proto");
 		if(index > 0){
			this.javaTypeBase = javaTypeBase.substring(0, index);
		}
		this.javaType = this.javaTypeBase;
		if ("repeated".equals(identifier)) {
			this.javaType = "List<"+StringUtils.getWrapper(this.javaType)+">";
		}
		
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getJavaType() {
		return javaType;
	}

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

	public boolean getPrimitive() {
		return StringUtils.isJavaType(javaTypeBase);
	}

	public String getJavaTypeBase() {
		return javaTypeBase;
	}

	public void setJavaTypeBase(String javaTypeBase) {
		this.javaTypeBase = javaTypeBase;
	}

	@Override
	public String toString() {
		return "\n\tProtocolField [identifier=" + identifier + ", type=" + type + ", name=" + name + ", comment="
				+ comment + "]";
	}
}
